
package com.phevos.usercenter.client.service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.phevos.usercenter.client.vo.UserValue;

/**
 * @author hjh
 */
public final class WebUtil
{

    private static final String NULL = "null";
    public static final String CAS_FILTER_USER = "edu.yale.its.tp.cas.client.filter.user";

    /**
     * ��ȡ��ǰ�û�
     * 
     * @param request HttpServletRequest
     * @return String
     */
    public static String getCurrentAccount(HttpServletRequest request)
    {
        HttpSession session = request.getSession();
        String account = (String)session.getAttribute(CAS_FILTER_USER);
        if (account == null)
        {
            account = NULL;
        }
        return account;
    }

    /**
     * ��õ�ǰuserId
     * 
     * @param request
     * @return
     */
    public static String getCurrentUserId(HttpServletRequest request)
    {
        String account = getCurrentAccount(request);
        if (account.equals(NULL))
        {
            return NULL;
        }
        UserValue user = Orgnization.getUserByAccount(account);
        if (user == null)
        {
            return NULL;
        }
        int id = user.getId();
        return "" + id;
    }
}
